package com.ruoyi.record.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.record.common.RecordConstant;
import com.ruoyi.record.domain.StepStudentVO;
import com.ruoyi.record.service.IWordStudyStepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.record.mapper.WordStudyStepStudentMapper;
import com.ruoyi.record.domain.WordStudyStepStudent;
import com.ruoyi.record.service.IWordStudyStepStudentService;

/**
 * 单词学习任务Service业务层处理
 */
@Service
public class WordStudyStepStudentServiceImpl implements IWordStudyStepStudentService 
{
    @Autowired
    private WordStudyStepStudentMapper wordStudyStepStudentMapper;

    @Autowired
    private IWordStudyStepService wordStudyStepService;

    /**
     * 查询单词学习任务
     * 
     * @param id 单词学习任务主键
     * @return 单词学习任务
     */
    @Override
    public WordStudyStepStudent selectWordStudyStepStudentById(Long id)
    {
        return wordStudyStepStudentMapper.selectWordStudyStepStudentById(id);
    }

    @Override
    public List<WordStudyStepStudent> selectStudentListByStep(Long main) {

        return wordStudyStepStudentMapper.selectStudentListByStep(main);
    }

    /**
     * 查询我的任务
     * 通过学生的ID
     * */
    @Override
    public List<WordStudyStepStudent> getMyStudyList(Long main, Long studentId){

        return wordStudyStepStudentMapper.getMyStudyList(main, studentId);
    }

    @Override
    public List<WordStudyStepStudent> getMyStudyList(Long studentId){
        return wordStudyStepStudentMapper.getMyStudyListAll(studentId);
    }

    /**
     * 开始我的任务
     * 记录主键
     * */
    @Override
    public void receiveMyStudy(Long id){
        wordStudyStepStudentMapper.receiveMyStudy(id);
    }

    /**
     * 查询单词学习任务列表
     * 
     * @param wordStudyStepStudent 单词学习任务
     * @return 单词学习任务
     */
    @Override
    public List<WordStudyStepStudent> selectWordStudyStepStudentList(WordStudyStepStudent wordStudyStepStudent)
    {
        return wordStudyStepStudentMapper.selectWordStudyStepStudentList(wordStudyStepStudent);
    }

    /**
     * 新增单词学习任务
     * 
     * @param wordStudyStepStudent 单词学习任务
     * @return 结果
     */
    @Override
    public String insertWordStudyStepStudent(WordStudyStepStudent wordStudyStepStudent)
    {
        wordStudyStepStudent.setTime(DateUtils.getNowDate());
        wordStudyStepStudent.setStatus(RecordConstant.STATUS_NORMAL);
        int inserted = wordStudyStepStudentMapper.insertWordStudyStepStudent(wordStudyStepStudent);
        //更新主表
        StepStudentVO studentVO = new StepStudentVO();
        studentVO.setId(wordStudyStepStudent.getMain());
        return updateMainTable(studentVO);
    }

    public String updateMainTable(StepStudentVO studentVO){
       return wordStudyStepService.updateStepStudentData(studentVO);
    }

    /**
     * 修改单词学习任务
     * 
     * @param wordStudyStepStudent 单词学习任务
     * @return 结果
     */
    @Override
    public int updateWordStudyStepStudent(WordStudyStepStudent wordStudyStepStudent)
    {
        return wordStudyStepStudentMapper.updateWordStudyStepStudent(wordStudyStepStudent);
    }

    /**
     * 批量删除单词学习任务
     * 
     * @param ids 需要删除的单词学习任务主键
     * @return 结果
     */
    @Override
    public int deleteWordStudyStepStudentByIds(Long[] ids)
    {
        return wordStudyStepStudentMapper.deleteWordStudyStepStudentByIds(ids);
    }

    /**
     * 删除单词学习任务信息
     * 
     * @param id 单词学习任务主键
     * @return 结果
     */
    @Override
    public int deleteWordStudyStepStudentById(Long id)
    {
        return wordStudyStepStudentMapper.deleteWordStudyStepStudentById(id);
    }
}
